cmake_minimum_required(VERSION 3.22)

project(libraries)
add_library(libraries INTERFACE)

enable_language(C ASM)

target_compile_definitions(libraries INTERFACE 
    USE_STDPERIPH_DRIVER
    AT32F403ACGT7
    $<$<CONFIG:Debug>:DEBUG>
)

target_include_directories(libraries INTERFACE
    core/inc
    drivers/inc
    cmsis/cm4/core_support
    cmsis/cm4/device_support
)

target_sources(libraries INTERFACE

    # 系统库
    core/src/syscalls.c
    core/src/sysmem.c
    core/src/at32f403a_407_int.c

    # 启动文件
    startup_at32f403a_407.s

    # 内核库
    cmsis/cm4/device_support/system_at32f403a_407.c

    # 驱动库
    drivers/src/at32f403a_407_acc.c
    drivers/src/at32f403a_407_adc.c
    drivers/src/at32f403a_407_bpr.c
    drivers/src/at32f403a_407_can.c
    drivers/src/at32f403a_407_crc.c
    drivers/src/at32f403a_407_crm.c
    drivers/src/at32f403a_407_dac.c
    drivers/src/at32f403a_407_debug.c
    drivers/src/at32f403a_407_dma.c
    drivers/src/at32f403a_407_emac.c
    drivers/src/at32f403a_407_exint.c
    drivers/src/at32f403a_407_flash.c
    drivers/src/at32f403a_407_gpio.c
    drivers/src/at32f403a_407_i2c.c
    drivers/src/at32f403a_407_misc.c
    drivers/src/at32f403a_407_pwc.c
    drivers/src/at32f403a_407_rtc.c
    drivers/src/at32f403a_407_sdio.c
    drivers/src/at32f403a_407_spi.c
    drivers/src/at32f403a_407_tmr.c
    drivers/src/at32f403a_407_usart.c
    drivers/src/at32f403a_407_usb.c
    drivers/src/at32f403a_407_wdt.c
    drivers/src/at32f403a_407_wwdt.c
    drivers/src/at32f403a_407_xmc.c
)

if(CMAKE_C_STANDARD LESS 11)
    message(ERROR "Generated code requires C11 or higher")
endif()
